int g(struct TreeNode* root, int* a)
{
    if (root == NULL)
    {
        return 0;
    }
    if (root->left == root->right)
    {
        return 1;
    }
    int n = g(root->left, a);
    int m = g(root->right, a);
    if ((n + m + 1) > *a)
    {
        *a = n + m + 1;
    }
    return n > m ? n + 1 : m + 1;
}


int diameterOfBinaryTree(struct TreeNode* root) {
    if (root->left == root->right)
        return 0;
    int a = 0;
    g(root, &a);
    return a - 1;

}